package com.yznote.cloudesk.file.controller;

import com.yznote.cloudesk.common.Anno.CollectLogs;
import com.yznote.cloudesk.common.constants.ModuleConstant;
import com.yznote.cloudesk.common.constants.YConstant;
import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.common.tokenShare.YTokenShare;
import com.yznote.cloudesk.file.server.GarbageServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Api(tags = "回收站管理")
@CollectLogs(moduleName = ModuleConstant.GARBAGE_MODULE)
@RequestMapping("/garbage")
public class GarbageController {
    @Autowired
    GarbageServer garbageServer;
    @Autowired
    YTokenShare yTokenShare;

    @ApiOperation("查询所有垃圾按时间")
    @GetMapping("/selectByTime")
    public Result selectByUserId(){
        //return Result.success(garbageServer.selectByTime(yTokenShare.get().getUserId()));
        return null;
    }
    //todo
//    @ApiOperation("查询所有垃圾按大小")
//    @GetMapping("/selectByV")
//    public Result selectByV(@RequestParam Long userId){
//        return null;
//    }

    @ApiOperation("单个文件放入回收站")
    @GetMapping("/insertGarbag")
    public Result insertGarbag(@RequestParam Long fileId){
        String msg = garbageServer.insertGarbage(fileId);
        if (msg != YConstant.SUCCESS) {
            return Result.build(null,500,msg);
        }
        return Result.success(null);
    }
    @ApiOperation("目录放入回收站(递归删除)")
    @GetMapping("/insertMoreGarbags")
    public Result insertMoreGarbags(@RequestParam Long fileId){
        String msg = garbageServer.insertMoreGarbages(fileId);
        if (msg != YConstant.SUCCESS) {
            return Result.build(null,500,msg);
        }
        return Result.success(null);
    }

    @ApiOperation("彻底删除文件")
    @GetMapping("/deleteGarbage")
    public Result deleteGarbage(@RequestParam Long fileId){
        try {
            garbageServer.deleteGarbage(fileId);
        } catch (Exception e) {
            return Result.build(null,500,"[error]删除失败");
        }
        return Result.success(null);
    }

    @ApiOperation("彻底删除目录(递归删除)")
    @GetMapping("/deleteMoreGarbages")
    public Result deleteMoreGarbages(@RequestParam Long fileId){
        try {
            garbageServer.deleteMoreGarbages(fileId);
        } catch (Exception e) {
            return Result.build(null,500,"[error]删除失败");
        }
        return Result.success(null);
    }

    @ApiOperation("清空回收站")
    @GetMapping("/deleteAllGarbages")
    public Result deleteAllGarbages(){
        try {
            garbageServer.deleteAllGarbages();
        } catch (Exception e) {
            return Result.build(null,500,"[error]删除失败");
        }
        return Result.success(null);
    }

    @ApiOperation("还原垃圾")
    @GetMapping("/reductionGarbage")
    public Result reductionGarbage(@RequestParam Long fileId){
        return null;
    }


}
